//
//  ZXAddSaleActivityController.m
//  qianke
//
//  Created by ZX on 2017/6/30.
//  Copyright © 2017年 ZX. All rights reserved.
//

#import "ZXAddSaleActivityController.h"
#import "AddressPickerView.h"
#import "ZXPickerView.h"
#import "ZXSaleActivityController.h"
#import "ZXTextView.h"
@interface ZXAddSaleActivityController ()<UITextViewDelegate,AddressPickerViewDelegate,myPickerViewDelegate,UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>
@property (weak, nonatomic) ZXTextView *beizhuTextView;
@property (weak, nonatomic) IBOutlet UIScrollView *myScrollView;
@property (nonatomic ,strong) AddressPickerView * pickerView;
@property (weak, nonatomic) IBOutlet UIButton *provinceBtn;
@property (weak, nonatomic) IBOutlet UITextField *provinceLabel;
@property (weak, nonatomic) IBOutlet UITextField *cityLabel;
@property (weak, nonatomic) IBOutlet UITextField *ouLabel;
@property (weak, nonatomic) IBOutlet UITextField *sexTield;
@property (weak, nonatomic) IBOutlet UITextField *carchexingFlied;
@property (weak, nonatomic) IBOutlet UITextField *carxinghaoFlied;
@property (weak, nonatomic) IBOutlet UITextField *guanzhuduFlied;
@property (weak, nonatomic) IBOutlet UIButton *sexBtn;
@property (weak, nonatomic) IBOutlet UIButton *carchexingBtn;
@property (weak, nonatomic) IBOutlet UIButton *carxinghaoBtn;
@property (weak, nonatomic) IBOutlet UIView *textBgView;
@property (weak, nonatomic) IBOutlet UIButton *guanzhuduBtn;
@property (weak, nonatomic) IBOutlet UITextField *yixiangyanseTextFlied;
@property (weak, nonatomic) IBOutlet UILabel *provinceLabel2;
@property (weak, nonatomic) IBOutlet UIView *xinghaoView;
@property (weak, nonatomic) IBOutlet UIView *zhuangbeiView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *yanseContraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *hightView;

@property (nonatomic, strong) UIView *maskLayer;
@property (nonatomic, strong) UIControl *control;
@property (nonatomic, strong) UITapGestureRecognizer *tap;
@property (nonatomic, strong) UIView *topViewShop;
/*lblTopTitle*/
@property(strong ,nonatomic)UILabel*lblTopTitle;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UIView *addressView;
@property (weak, nonatomic) IBOutlet UIButton *jiantouBtn1;
@property (weak, nonatomic) IBOutlet UIButton *jiantouBtn2;
@property (weak, nonatomic) IBOutlet UIButton *jiantouBtn3;
@property (weak, nonatomic) IBOutlet UIButton *jiantouBtn4;
@property (weak, nonatomic) IBOutlet UIButton *jiantouBtn5;
/*_setupCodeArr*/
@property(strong ,nonatomic)NSMutableArray*array;
/*_setupCodeArr*/
@property(strong ,nonatomic)UIPickerView *thePicker;
- (IBAction)sureBthnClick:(UIButton *)sender;
- (IBAction)resetBtnClick:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UILabel *yixiangyanseLabel;
@property (weak, nonatomic) IBOutlet UILabel *yixiangzhuangbeiLabel;
@property (weak, nonatomic) IBOutlet UIButton *resetBtn;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;
@property (weak, nonatomic) IBOutlet UITextField *nameFlied;
@property (weak, nonatomic) IBOutlet UITextField *phoneFlied;

/**<>*/
@property(strong ,nonatomic)UIButton*typeBtn;
/**<>*/
@property(assign ,nonatomic)NSInteger type;
@property(assign ,nonatomic)NSInteger lastPosition;
/**<>*/
@property(copy ,nonatomic)NSArray * arr;
@property(strong ,nonatomic)NSMutableArray * modelNameArr;
@property(strong ,nonatomic)NSMutableArray * modelCodeArr;
@property(strong ,nonatomic)NSMutableArray * setupCodeArr;
@property(strong ,nonatomic)NSMutableArray * carColorNameArr;

/*provinceText*/
@property(copy ,nonatomic)NSString*provinceText;
@property(copy ,nonatomic)NSString*cityText;
@property(copy ,nonatomic)NSString*careText;
@end

@implementation ZXAddSaleActivityController
#define     KeyWindow     [[UIApplication sharedApplication] keyWindow]
@synthesize maskLayer,control,tap;
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.pickerView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    if (!_arr) {
        _arr = [[NSArray alloc]init];
    }
    self.title = @"添加意向客户";
    _beizhuTextView.placeHolder = @"hhh";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
    _addressView.hidden = YES;
    if (_fromType) {
        self.title = @"销售机会详情";
//        _ideaColorName = @"";
        if (!_equipLevelCode.length) {
            _xinghaoView.hidden = YES;
            _yanseContraint.constant = 0;
            _hightView.constant = 301;
            _zhuangbeiView.hidden = YES;
        }else{
            if (!_ideaColorName.length) {
                _xinghaoView.hidden = YES;
                _yanseContraint.constant = 0;
                _hightView.constant = 301;
            }
        }
//        _hightView.constant = 300;
        _addressView.hidden = NO;
        _provinceLabel2.text = @"地址:";
        [_resetBtn setTitle:@"查看销售活动" forState:UIControlStateNormal];
        [_sureBtn setTitle:@"转订单" forState:UIControlStateNormal];
        self.title = @"意向客户信息";
        _myScrollView.userInteractionEnabled = NO;
        _nameFlied.text = _name;
        _sexTield.text = _sex;
        _phoneFlied.text = _phone;
        _provinceLabel.text = _province;
        _cityLabel.text = _city;
        _ouLabel.text = _area;
        _carchexingFlied.text = _chexing;
        _carxinghaoFlied.text = _xinghao;
        _addressLabel.text = _address;
        _guanzhuduFlied.text = _equipLevelCode;
        if (_beizhuxinxi.length) {
            _beizhuTextView.text = _beizhuxinxi;
        }else {
            _beizhuTextView.text = @"无";
        }
        _yixiangzhuangbeiLabel.text = @"意向装备";
        _yixiangyanseLabel.text = @"意向颜色";
        _yixiangyanseTextFlied.text = _ideaColorName;
        _jiantouBtn1.hidden = YES;
        _jiantouBtn2.hidden = YES;
        _jiantouBtn3.hidden = YES;
        _jiantouBtn4.hidden = YES;
        _jiantouBtn5.hidden = YES;
    }
   
    if (!_array) {
        _array = [[NSMutableArray alloc]init];
    }
    [self loadData];
    
    [self creatShopPicker];
    
    [_phoneFlied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
- (void)textFieldDidChange:(UITextField *)textField
{
    if (textField == _phoneFlied) {
        if (textField.text.length > 11) {
            textField.text = [textField.text substringToIndex:11];
        }
    }
}
- (void)creatShopPicker{
    UIPickerView *thePicker=[[UIPickerView alloc]initWithFrame:CGRectMake(0, ScreenHeight-216, ScreenWidth, 216)];
    _thePicker = thePicker;
    thePicker.showsSelectionIndicator = YES;
    thePicker.tag=110;
    thePicker.delegate = self;
    thePicker.dataSource = self;
    _thePicker.hidden = YES;
    thePicker.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:thePicker];
    UIView * topViewShop = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight-216, ScreenWidth, 44)];
    _topViewShop = topViewShop;
    topViewShop.backgroundColor = [UIColor colorWithWhite:.95 alpha:1];
    [self.view addSubview:topViewShop];
    
    UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    btnCancel.frame = CGRectMake(0, 0, 80, 44);
    [btnCancel setTitle:@"取消" forState:UIControlStateNormal];
    [btnCancel setTitleColor:baseBlueColor forState:UIControlStateNormal];
    [topViewShop addSubview:btnCancel];
    [btnCancel addTarget:self action:@selector(btnCancelClick) forControlEvents:UIControlEventTouchUpInside];
    _topViewShop.hidden = YES;
    UILabel*lblTopTitle = [UILabel createLabelWithFrame:CGRectMake((ScreenWidth-100)/2, 0, 100, 44) font:[UIFont systemFontOfSize:17] textColor:baseBlueColor];
    lblTopTitle.textAlignment = NSTextAlignmentCenter;
    _lblTopTitle = lblTopTitle;
    [topViewShop addSubview:lblTopTitle];
    
//    lblTopTitle.text = @"选择门店";
    
    UIButton *btnFirm = [[UIButton alloc]init];
    btnFirm.frame = CGRectMake(ScreenWidth-80, 0, 80, 44);
    [btnFirm setTitle:@"确定" forState:UIControlStateNormal];
    [btnFirm setTitleColor:baseBlueColor forState:UIControlStateNormal];
    [topViewShop addSubview:btnFirm];
    [btnFirm addTarget:self action:@selector(btnFirmClickShop) forControlEvents:UIControlEventTouchUpInside];
}
- (void)btnFirmClickShop{
    _myScrollView.userInteractionEnabled = YES;
    NSInteger idx = [_thePicker selectedRowInComponent:0];
    NSLog(@"btnFirmClickShop=idx%ld",(long)idx);
    if (_type == 1000002) {
        NSString * str =  _modelNameArr[idx];
        NSMutableArray * temArr = [NSMutableArray array];
        for (int i = 0; i<_arr.count; i++) {
            if ([[_arr[i] objectForKey:@"modelName"]isEqualToString:str]) {
                [temArr addObject: [_arr[i] objectForKey:@"modelCode"]];
            }
        }
        NSSet *set = [NSSet setWithArray:temArr];
        NSArray * temArr2 = [set allObjects];
        _modelCodeArr = [temArr2 mutableCopy];
        NSLog(@"_modelNameArr==%@",_modelCodeArr);
        _carchexingFlied.text = _modelNameArr[idx];
        _carxinghaoFlied.text = @"";
        _guanzhuduFlied.text = @"";
        _yixiangyanseTextFlied.text = @"";
    }else if (_type == 1000001){
        if (idx) {
            _sexTield.text = @"女";
        } else{
            _sexTield.text = @"男";
        }
        _yixiangyanseTextFlied.text = @"";
    }else if (_type == 1000003){
        _carxinghaoFlied.text = _modelCodeArr[idx];
        _guanzhuduFlied.text = @"";
         _yixiangyanseTextFlied.text = @"";
    }else if (_type == 1000004){
        _guanzhuduFlied.text = _setupCodeArr[idx];
         _yixiangyanseTextFlied.text = @"";
    }else{
        _yixiangyanseTextFlied.text = _carColorNameArr[idx];
    }
    _thePicker.hidden = YES;
    _topViewShop.hidden = YES;
    NSLog(@"%ld",(long)idx);
    [_array removeAllObjects];
}
- (void)btnCancelClick{
    _myScrollView.userInteractionEnabled = YES;
    NSLog(@"btnCancelClick");
    _thePicker.hidden = YES;
    _topViewShop.hidden = YES;
    [_array removeAllObjects];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    NSLog(@"%lu",(unsigned long)_array.count);
    return _array.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (_array) {
        return _array[row];
    }else{
        return nil;
    }
}
-(void)loadData{
    //反序列化
    NSData * rData = [[NSUserDefaults standardUserDefaults] objectForKey:AddCostomerArr];
    NSArray * arr = [NSKeyedUnarchiver unarchiveObjectWithData:rData];
    my_AppDelegate.carArr = [arr mutableCopy];
//    arr = nil;
    if (my_AppDelegate.carArr.count) {
        _arr = [my_AppDelegate.carArr mutableCopy];
        NSMutableArray * nameArr= [NSMutableArray array];

        for (int i = 0; i<_arr.count; i++) {
            NSString * str = [_arr[i] objectForKey:@"modelName"];
            [nameArr addObject:str];
        }
        NSLog(@"_arr=%@",_arr);
        NSSet *set = [NSSet setWithArray:nameArr];
        NSArray *resultArray = [set allObjects];
        _modelNameArr = [resultArray mutableCopy];
        _array = [_modelNameArr mutableCopy];
        [[NSUserDefaults standardUserDefaults]synchronize];
        NSLog(@"_array==%@",_array);
        [_thePicker reloadAllComponents];
    }else{
        AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
        // 2.设置网络状态改变后的处理
        [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
            // 当网络状态改变了, 就会调用这个block
            switch (status) {
                case AFNetworkReachabilityStatusUnknown: // 未知网络
                    NSLog(@"未知网络");
                    break;
                    
                case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
                    NSLog(@"没有网络(断网)");
                    break;
                    
                case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                    NSLog(@"手机自带网络");
                    break;
                    
                case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                    NSLog(@"WIFI");
                    break;
            }
        }];
        
        // 3.开始监控
        [mgr startMonitoring];

        NSMutableArray * nameArr= [NSMutableArray array];
        NSString * urlStr = [NSString stringWithFormat:@"%@scrmForApp/carModelColorSetup",ZXBaseURL];
        NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];
        [request setValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
        [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
            _arr = [data objectForKey:@"data"];
            NSLog(@"_arr==%@",_arr);
            for (int i = 0; i<_arr.count; i++) {
                NSString * str = [_arr[i] objectForKey:@"modelName"];
                [nameArr addObject:str];
            }
            NSLog(@"nameArr=%@",nameArr);
            NSSet *set = [NSSet setWithArray:nameArr];
            NSArray *resultArray = [set allObjects];
            _modelNameArr = [resultArray mutableCopy];
            _array = [_modelNameArr mutableCopy];
            
            //序列化
            NSData * wData = [NSKeyedArchiver archivedDataWithRootObject:_arr];
            [[NSUserDefaults standardUserDefaults] setObject:wData forKey:AddCostomerArr];
            [[NSUserDefaults standardUserDefaults] synchronize];

            [_thePicker reloadAllComponents];
        } failure:^(NSError *error) {
            [self loadData];
        }];
    }
}

- (IBAction)choseBtnClick:(UIButton*)sender {
    [SVProgressHUD dismiss];
    [self.view endEditing:YES];
    _myScrollView.userInteractionEnabled = NO;
    [_array removeAllObjects];
    sender.enabled = NO;
    NSLog(@"%ld",(long)sender.tag);
    NSInteger idx = [_thePicker selectedRowInComponent:0];
    _type = sender.tag;
    NSLog(@"type==%ld",(long)idx);
    sender.selected = !sender.selected;
 
    if (sender.tag == 1000005) {
        _thePicker.hidden = YES;
        _topViewShop.hidden = YES;
        [self.view bringSubviewToFront:_pickerView];
        _myScrollView.userInteractionEnabled = YES;
        if (sender.selected) {
            [self.pickerView show];
        }else{
            [self.pickerView hide];
        }
    }
    NSArray * array2 = @[@"男",@"女"];
    switch (sender.tag) {
        case 1000001:
            NSLog(@"客户性别");
            _lblTopTitle.text = @"性别";
            if (1) {
                _array = [array2 mutableCopy];
                [_thePicker reloadAllComponents];
                _thePicker.hidden = NO;
                _topViewShop.hidden = NO;
            }
            break;
        case 1000002:
                if (_arr.count) {
                    if ([_arr[0] isEqual:[NSNull null]]) {
                        _thePicker.hidden = YES;
                        _topViewShop.hidden = YES;
                        _myScrollView.userInteractionEnabled = YES;
                        return;
                    }else{
                        _lblTopTitle.text = @"意向车型";
                        _array = [_modelNameArr mutableCopy];
                        NSLog(@"%@",_array);
                        if (_array.count) {
                            if ([_array[0] isEqual:[NSNull null]]) {
                                _myScrollView.userInteractionEnabled = YES;
                                return;
                            }else{
                                _thePicker.hidden = NO;
                                _topViewShop.hidden = NO;
                                [_thePicker reloadAllComponents];
                            }
                        }else{
                            _myScrollView.userInteractionEnabled = YES;
                            return;
                        }

                    }
                }else{
                    _thePicker.hidden = YES;
                    _topViewShop.hidden = YES;
                    _myScrollView.userInteractionEnabled = YES;
                    return;
                }
            NSLog(@"意向车型");
            break;
            
        case 1000003:
            if (_carchexingFlied.text.length>0) {
                _thePicker.hidden = NO;
                _topViewShop.hidden = NO;
                _array = [_modelCodeArr mutableCopy];
                NSLog(@"%@",_array);
                if (_array.count) {
                    [_thePicker reloadAllComponents];
                }
                _lblTopTitle.text = @"意向型号";
            }else{
                _myScrollView.userInteractionEnabled = YES;
                [SVProgressHUD showErrorWithStatus:@"请先选择车型"];
            }
            
            NSLog(@"意向型号");
            break;
            
        case 1000004:
            if (1) {
                if (_carchexingFlied.text.length>0&&_carxinghaoFlied.text.length>0) {
                    NSMutableArray * temArr = [NSMutableArray array];
                    for (int i = 0; i<_arr.count; i++) {
                        if ([[_arr[i] objectForKey:@"modelName"]isEqualToString:_carchexingFlied.text] &&[[_arr[i] objectForKey:@"modelCode"]isEqualToString:_carxinghaoFlied.text]){
                            [temArr addObject: [_arr[i] objectForKey:@"setupCode"]];
                        }
                    }
                    NSSet *set = [NSSet setWithArray:temArr];
                    NSArray * temArr2 = [set allObjects];
                    _setupCodeArr = [temArr2 mutableCopy];
                    _array = [_setupCodeArr mutableCopy];
                    _lblTopTitle.text = @"意向颜色";
                    NSLog(@"%@",_array);
                    if (_array.count) {
                        if ([_array[0] isEqual:[NSNull null]]) {
                            _myScrollView.userInteractionEnabled = YES;
                            [SVProgressHUD showErrorWithStatus:@"该条件下没有装备"];
                        }else{
                        _thePicker.hidden = NO;
                        _topViewShop.hidden = NO;
                        [_thePicker reloadAllComponents];
                        }
                    }else{
                        _myScrollView.userInteractionEnabled = YES;
                        [SVProgressHUD showErrorWithStatus:@"该条件下没有装备"];
                    }
                }else{
                    _myScrollView.userInteractionEnabled = YES;
                    [SVProgressHUD showErrorWithStatus:@"请先选择车型和型号"];
                }
                }
            NSLog(@"关注度");
            break;
        case 1000009:
            if (1) {
                if (_carxinghaoFlied.text.length>0&&_carchexingFlied.text.length>0&&_guanzhuduFlied.text.length>0) {
                    _thePicker.hidden = NO;
                    _topViewShop.hidden = NO;
                    NSMutableArray * temArr = [NSMutableArray array];
                    for (int i = 0; i<_arr.count; i++) {
                        if ([[_arr[i] objectForKey:@"modelName"]isEqualToString:_carchexingFlied.text] &&[[_arr[i] objectForKey:@"modelCode"]isEqualToString:_carxinghaoFlied.text]&&[[_arr[i] objectForKey:@"setupCode"]isEqualToString:_guanzhuduFlied.text]){
                            [temArr addObject: [_arr[i] objectForKey:@"carColorName"]];
                        }
                    }
                    if (temArr.count) {
                        NSSet *set = [NSSet setWithArray:temArr];
                        NSArray * temArr2 = [set allObjects];
                        if (temArr2.count) {
                            _carColorNameArr= [temArr2 mutableCopy];
                            _array = [_carColorNameArr mutableCopy];
                            NSLog(@"%@",_array[0]);
                            NSLog(@"%lu",(unsigned long)_array.count);
                            if (_array.count) {
                                if ([_array[0]  isEqual:[NSNull null]]) {
                                    _myScrollView.userInteractionEnabled = YES;
                                    [SVProgressHUD showErrorWithStatus:@"该条件下没有颜色"];
                                    _thePicker.hidden = YES;
                                    _topViewShop.hidden = YES;
                                }else{
                                    [_thePicker reloadAllComponents];
                                }
                            }
                        }
                    }
                }else{
                    _myScrollView.userInteractionEnabled = YES;
                    [SVProgressHUD showErrorWithStatus:@"请先选择车型、型号和装备"];
                }
            }
            NSLog(@"关注度");
            break;
            
        default:
            
            break;
    }
    sender.enabled = YES;
}
- (AddressPickerView *)pickerView{
    if (!_pickerView) {
        _pickerView = [[AddressPickerView alloc]initWithFrame:CGRectMake(0, ScreenHeight , ScreenWidth, 215)];
        _pickerView.delegate = self;
    }
    return _pickerView;
}
-(void)zxsureBtnClickReturnString:(NSString *)string{
    NSLog(@"string==%@",string);
    switch (_type) {
        case 1000001:
            NSLog(@"客户性别");
            _sexTield.text = string;
            [_contentDic setValue:string forKey:@"sex"];
            [self choseBtnClick:_sexBtn];
            [_array removeAllObjects];
            break;
        case 1000002:
            _carchexingFlied.text = string;
            [_contentDic setValue:string forKey:@"chexing"];

            [self choseBtnClick:_carchexingBtn];
            NSLog(@"意向车型");
            break;
            
        case 1000003:
            NSLog(@"意向型号");
            _carxinghaoFlied.text = string;
            [_contentDic setValue:string forKey:@"xinghao"];

            [self choseBtnClick:_carxinghaoBtn];
            break;
            
        case 1000004:
            _guanzhuduFlied.text = string;
            [_contentDic setValue:string forKey:@"guanzhudu"];

            [self choseBtnClick:_guanzhuduBtn];
            NSLog(@"关注度");
            break;
            
        default:
            break;
    }
    [self action_removeMask];
    
}

-(void)zxcancelBtnClick{
    _myScrollView.userInteractionEnabled = YES;

    [self action_removeMask];
    switch (_type) {
        case 1000001:
            NSLog(@"客户性别");
            [self choseBtnClick:_sexBtn];
            [_array removeAllObjects];
            break;
        case 1000002:
            [self choseBtnClick:_carchexingBtn];
            NSLog(@"意向车型");
            break;
            
        case 1000003:
            NSLog(@"意向型号");
            [self choseBtnClick:_carxinghaoBtn];
            break;
            
        case 1000004:
            [self choseBtnClick:_guanzhuduBtn];
            NSLog(@"关注度");
            break;
            
        default:
            break;
    }
    
    NSLog(@"点击了取消按钮eee");
    NSLog(@"%@",_typeBtn.selected?@"YES":@"NO");
    
}

#pragma mark - AddressPickerViewDelegate
- (void)cancelBtnClick{
    NSLog(@"点击了取消按钮");
    [self action_removeMask];
    
    [self choseBtnClick:_provinceBtn];
}
- (void)sureBtnClickReturnProvince:(NSString *)province City:(NSString *)city Area:(NSString *)area{
    [self action_removeMask];
    _myScrollView.userInteractionEnabled = YES;
    _provinceText = province;
    _cityText = city;
    _careText = area;
    if ([province length]>5) {
        province = [province substringWithRange: NSMakeRange(0,2)];
    }
    if ([city length]>3) {
        city = [NSString stringWithFormat:@"%@...", [city substringWithRange: NSMakeRange(0,3)]];
    }
    if ([area length]>3) {
        area = [NSString stringWithFormat:@"%@...",[area substringWithRange: NSMakeRange(0,3)]];
    }
    _provinceLabel.text =[NSString stringWithFormat:@"%@",province];
    _cityLabel.text =[NSString stringWithFormat:@"%@",city];
    _ouLabel.text =[NSString stringWithFormat:@"%@",area];
    [_contentDic setValue:province forKey:@"province"];
    [_contentDic setValue:city forKey:@"city"];
    [_contentDic setValue:area forKey:@"area"];
    [self choseBtnClick:_provinceBtn];
}

- (void)addMaskLayer{
    
    // 添加遮罩
    maskLayer = [UIView  new];
    [maskLayer setFrame:[[UIScreen mainScreen] bounds]];
    [maskLayer setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]];
    [self.view addSubview:maskLayer];
    [self.view addSubview:control];
    
}

- (void)action_removeMask{
    // 移除全屏点击事件
    [control removeFromSuperview];
    [maskLayer removeFromSuperview];
}

/**
 *  键盘将要显示
 *
 *  @param notification 通知
 */
-(void)keyboardWillShow:(NSNotification *)notification
{
    CGRect frame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
     if (_beizhuTextView.isFirstResponder) {
        
        _myScrollView.contentOffset = CGPointMake(0,697-frame.origin.y);
        
    }
    
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [SVProgressHUD dismiss];
    [self.view endEditing:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int currentPostion = scrollView.contentOffset.y;
    if (currentPostion - _lastPosition > 80) {
        _lastPosition = currentPostion;
    }
    else if (_lastPosition - currentPostion > 80)
    {
        _lastPosition = currentPostion;

    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    
    return YES;
}
/**
 *  键盘将要隐藏
 *
 *  @param notification 通知
 */
-(void)keyboardWillHidden:(NSNotification *)notification
{
    CGRect frame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    NSLog(@"frame隐藏==%@",NSStringFromCGRect(frame));
    _myScrollView.contentOffset = CGPointMake(0,  0);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    
    if ([text isEqualToString:@"\n"]) {
        
        [textView resignFirstResponder];
        return NO;
    }
    
    return YES;
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    if (alertView.tag ==9999999) {
        return;
    }
    UITextField *txt = [alertView textFieldAtIndex:0];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    BOOL isName3 = [ZXToolObj isEmpty:txt.text];
    if (isName3) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请输入正确的金额数目" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil,nil];
        alert.tag = 9999999;
        [alert show];
       
        return;
    }
    
    [param setValue:txt.text forKey:@"retailPrice"];
    [param setValue:[NSString stringWithFormat:@"%d",_noticeId.intValue] forKey:@"ideaGuestId"];
    NSString * urlStr = [NSString stringWithFormat:@"%@scrmForApp/guestOrder/trunOrder",ZXBaseURL];
    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"POST";
    [request setValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    NSData *data = [NSJSONSerialization dataWithJSONObject:param options:NSJSONWritingPrettyPrinted error:nil];
    request.HTTPBody = data;
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]);
        NSString * recultCode = [dic objectForKey:@"msgCod"];
        NSString * message = [dic objectForKey:@"message"];
        if ([recultCode isEqualToString:@"S0002"]) {
            
        }else {
            dispatch_async(dispatch_get_main_queue(), ^{
                _sureBtn.enabled = YES;
                [SVProgressHUD showErrorWithStatus:message];
            });
            return ;
        }
        if ([message containsString:@"成功"]) {
            [SVProgressHUD showSuccessWithStatus:message];
            dispatch_async(dispatch_get_main_queue(), ^{
            [self.navigationController popViewControllerAnimated:NO];
            });
        }else{
            [SVProgressHUD showErrorWithStatus:message];
        }

    }];
    [task resume];
}
- (IBAction)sureBthnClick:(UIButton *)sender {
    
    if (_fromType) {
        _sureBtn.enabled = NO;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请输入客户购买车辆价格" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
        [alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
        UITextField *txt = [alert textFieldAtIndex:0];
        txt.keyboardType = UIKeyboardTypeDecimalPad;
        [alert show];
        _sureBtn.enabled = YES;
                NSLog(@"转订单");
    } else{
        NSString * carColorId;
        NSString * ideaModelId;
        NSString * setupId;
        for (int j = 0; j<_arr.count; j++) {
            NSString * modelName = [_arr[j] objectForKey:@"modelName"];
            NSString * modelCode = [_arr[j] objectForKey:@"modelCode"];
            NSString * setupCode = [_arr[j] objectForKey:@"setupCode"];
            NSString * carColorName = [_arr[j] objectForKey:@"carColorName"];
//            setupId = [NSString stringWithFormat:@"%@",[_arr[j] objectForKey:@"setupId"]];
            if (_yixiangyanseTextFlied.text.length) {
                if ([modelName isEqualToString:_carchexingFlied.text]&&[modelCode isEqualToString:_carxinghaoFlied.text]&&[setupCode isEqualToString:_guanzhuduFlied.text]&&[carColorName isEqualToString:_yixiangyanseTextFlied.text]) {
                    carColorId = [_arr[j] objectForKey:@"carColorId"];
                    ideaModelId = [_arr[j] objectForKey:@"modelId"];
                    setupId = [NSString stringWithFormat:@"%@",[_arr[j] objectForKey:@"setupId"]];
                    break;
                }
            }else if(_guanzhuduFlied.text.length){
                if ([modelName isEqualToString:_carchexingFlied.text]&&[modelCode isEqualToString:_carxinghaoFlied.text]&&[setupCode isEqualToString:_guanzhuduFlied.text]) {
                    carColorId = [_arr[j] objectForKey:@"carColorId"];
                    ideaModelId = [_arr[j] objectForKey:@"modelId"];
                    setupId = [NSString stringWithFormat:@"%@",[_arr[j] objectForKey:@"setupId"]];
                }
                
            }else{
                if ([modelName isEqualToString:_carchexingFlied.text]&&[modelCode isEqualToString:_carxinghaoFlied.text]) {
                    carColorId = [_arr[j] objectForKey:@"carColorId"];
                    ideaModelId = [_arr[j] objectForKey:@"modelId"];
//                    setupId = [NSString stringWithFormat:@"%@",[_arr[j] objectForKey:@"setupId"]];

                }
                
            }
        }
        
        if (!_nameFlied.text.length) {
            [SVProgressHUD showErrorWithStatus:@"客户姓名不能为空"];
            return;
        }
        BOOL isName = [ZXToolObj isEmpty:_nameFlied.text];
        if (isName) {
             [SVProgressHUD showErrorWithStatus:@"客户姓名不能为空"];
            return;
        }
        if (!_sexTield.text.length) {
            [SVProgressHUD showErrorWithStatus:@"请选择性别"];
            return;
        }
        if (_phoneFlied.text.length!=11) {
            [SVProgressHUD showErrorWithStatus:@"请输入正确的手机号"];
            return;
        }
        if (!_provinceLabel.text.length) {
            [SVProgressHUD showErrorWithStatus:@"请选择省市区"];
            return;
        }
        if (!_carchexingFlied.text.length) {
            [SVProgressHUD showErrorWithStatus:@"请选择意向车型"];
            return;
        }
        if (!_carxinghaoFlied.text.length) {
            [SVProgressHUD showErrorWithStatus:@"请选择意向型号"];
            return;
        }
//        if (!_guanzhuduFlied.text.length) {
//            [SVProgressHUD showErrorWithStatus:@"请选择装备"];
//            return;
//        }

//        if (!_sexTield.text.length||!_nameFlied.text.length||!_provinceLabel.text.length||!_phoneFlied.text.length||!_carchexingFlied.text.length||!_carxinghaoFlied.text.length||!_guanzhuduFlied.text.length) {
//            return;
//        }
        _sureBtn.enabled = NO;
        NSMutableDictionary *param = [NSMutableDictionary dictionary];
        [param setValue:[NSString stringWithFormat:@"%@%@%@",_provinceText,_cityText,_careText] forKey:@"address"];
        [param setValue:my_AppDelegate.userName forKey:@"builder"];
        [param setValue:ideaModelId forKey:@"ideaModelId"];//////ModelId
        [param setValue:_carchexingFlied.text forKey:@"ideaModelName"];/////modelName
        [param setValue:my_AppDelegate.uid forKey:@"adviserNo"];
        [param setValue:my_AppDelegate.userName forKey:@"adviser"];
        [param setValue:_nameFlied.text forKey:@"guestName"];
        [param setValue:_sexTield.text forKey:@"sex"];
        [param setValue:_phoneFlied.text forKey:@"handPhone"];
        [param setValue:my_AppDelegate.dealerId forKey:@"dealerId"];
        [param setValue:_careText forKey:@"area"];
        if (_yixiangyanseTextFlied.text.length) {
            [param setValue:_yixiangyanseTextFlied.text forKey:@"ideaColorName"];///////carColorName
            [param setValue:carColorId forKey:@"ideaColorId"];
        }else{
             [param setValue:@"" forKey:@"ideaColorName"];
            [param setValue:@"" forKey:@"ideaColorId"];
        }
        if (setupId.length) {
            [param setValue:setupId forKey:@"equipLevel"];
        }else{
            [param setValue:@"" forKey:@"equipLevel"];
            
        }
        NSLog(@"param = %@",param);
        
        NSURL *url = [NSURL URLWithString:ZXaddCustomURL];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        request.HTTPMethod = @"POST";
        [request setValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        NSData *data = [NSJSONSerialization dataWithJSONObject:param options:NSJSONWritingPrettyPrinted error:nil];
        request.HTTPBody = data;
        
        
        
//   ////////////////////////////////////////////////////////
        
        /*
         test
        [HTTPHelper PostmutableRequest:request success:^(NSDictionary *data) {
            if (!data||[data isEqual:[NSNull null]]) {
                _sureBtn.enabled = YES;
                return ;
            };
            
        } failure:^(NSError *error) {
        
        }];
        
        
        */
        
//   ////////////////////////////////////////////////////////

        
        
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (!data||[data isEqual:[NSNull null]]) {
                _sureBtn.enabled = YES;
                return ;
            }
            NSDictionary * dicc = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSString * recultCode = [dicc objectForKey:@"msgCod"];
            NSString * string = [dicc objectForKey:@"message"];
            if ([recultCode isEqualToString:@"S0002"]) {
                
            }else {
                dispatch_async(dispatch_get_main_queue(), ^{
                    _sureBtn.enabled = YES;
                    [SVProgressHUD showErrorWithStatus:string];
                });
                return ;
            }
            if ([string isEqual:[NSNull null]]||!string) {
                return ;
            }
            if ([string containsString:@"成功"]) {
                [SVProgressHUD showSuccessWithStatus:string];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.navigationController popViewControllerAnimated:NO];
                });
            }else{
                dispatch_async(dispatch_get_main_queue(), ^{
                    _sureBtn.enabled = YES;
                    [SVProgressHUD showErrorWithStatus:string];
                });
            }
        }];
        
    }
    
}

- (IBAction)resetBtnClick:(UIButton *)sender {
    if (_fromType) {
        ZXSaleActivityController * saleVc = [ZXSaleActivityController new];
        saleVc.chanceId = _chanceId;
        saleVc.title = @"销售活动";
        saleVc.view.backgroundColor = baseBackgroundColor;
        [self.navigationController pushViewController:saleVc animated:YES];
    }else{
        _nameFlied.text = @"";
        _phoneFlied.text = @"";
        _sexTield.text = @"";
        _provinceLabel.text = @"";
        _cityLabel.text = @"";
        _ouLabel.text = @"";
        _carchexingFlied.text = @"";
        _carxinghaoFlied.text = @"";
        _guanzhuduFlied.text = @"";
        _beizhuTextView.text = @"";
        _yixiangyanseTextFlied.text = @"";
        NSLog(@"重置");
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}


- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}




-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeLeft;
}


//设置样式
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

//设置是否隐藏
- (BOOL)prefersStatusBarHidden {
    //    [super prefersStatusBarHidden];
    return NO;
}

//设置隐藏动画
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationNone;
}



@end
